/*
 *  POJ1426: Find The Multiple
 */

/*-------- Includes --------*/
#include <iostream>
#include <queue>

using namespace std;

/*-------- Types --------*/
struct Pack {
    int k;  // kth solution
    int r;  // remainder
public:
    Pack() {}
    Pack(int kk, int rr) : k(kk), r(rr) {}
};

/*-------- Global Variables --------*/

/*-------- Function Prototypes --------*/

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int n;
    int m[128];

    while (cin >> n && n) {
        // special case: n=1
        if (n == 1) {cout << "1" << endl; continue;}

        queue<Pack> que;
        Pack        pk;

        int rten = 10 % n;  // remainder of 10 divided by n

        // add first element
        que.push(Pack(1, 1));

        while (!que.empty()) {
            pk = que.front(); que.pop();

            // base case: find the solution
            if (pk.r == 0) break;

            // two entrances
            int R;

            R = (pk.r * rten) % n;
            que.push(Pack(pk.k * 2, R));

            R = (R + 1) % n;
            que.push(Pack(pk.k * 2 + 1, R));
        }

        // generate m
        int k = pk.k;
        int l = 0;
        while (k > 0) {
            if (k % 2) m[l++] = 1;
            else       m[l++] = 0;

            k /= 2;
        }

        // print
        for (int i = l - 1; i >= 0; i--) cout << m[i];
        cout << endl;
    }

    return 0;
}

/*-------- Functions --------*/

